package com.example.visit.adapter

import androidx.databinding.DataBindingUtil
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.example.base.entity.VisitBeanItem
import com.example.visit.R
import com.example.visit.databinding.ItemVisitBinding

class VisitAdapter: BaseQuickAdapter<VisitBeanItem, BaseViewHolder>(R.layout.item_visit) {
    override fun onItemViewHolderCreated(viewHolder: BaseViewHolder, viewType: Int) {
        super.onItemViewHolderCreated(viewHolder, viewType)
        DataBindingUtil.bind<ItemVisitBinding>(viewHolder.itemView)
    }
    override fun convert(helper: BaseViewHolder, item: VisitBeanItem) {
        val binding = DataBindingUtil.getBinding<ItemVisitBinding>(helper.itemView)!!
        binding.bean = item
        //待审核、已通过、已完成、驳回
        binding.visitStatus.apply {
            when(item.visitStatus){
                "待审核"->{
                    setTextColor(context.getColor(R.color.orange))
                    setBackgroundResource(R.drawable.shape_weihu)
                }
                "已通过"->{
                    setTextColor(context.getColor(R.color.green))
                    setBackgroundResource(R.drawable.shape_status)
                }
                "已完成"->{
                    setTextColor(context.getColor(R.color.darkgreen))
                    setBackgroundResource(R.drawable.shape_solid_lightgray)
                }
                "驳回"->{
                    setTextColor(context.getColor(R.color.redfont))
                    setBackgroundResource(R.drawable.shape_solid_red)
                }
            }
        }

        if (item.requestParking){
            binding.visitCar.setImageResource(R.drawable.ic_action_nocar)
            binding.visitCarNo.apply {
                setText("已申请车位")
                setTextColor(context.getColor(R.color.blue))
            }
        }else{
            binding.visitCar.setImageResource(R.drawable.ic_action_nocar)
            binding.visitCarNo.apply {
                setText("未申请车位")
                setTextColor(context.getColor(R.color.darkgray))
            }
        }
    }
}